package com.lkl.demo.common.exception;

import com.lkl.demo.common.result.ResponseEnum;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * 业务异常处理类
 */
@Data
@NoArgsConstructor
public class BusinessException extends RuntimeException {

    //状态码
    private Integer code;

    //错误消息
    private String message;

    /**
     * @param message 错误信息
     */
    public BusinessException(String message) {
        this.code = ResponseEnum.ERROR.getCode();
        this.message = message;
    }

    /**
     * @param message 错误信息
     * @param code    错误码
     */
    public BusinessException(String message, Integer code) {
        this.code = code;
        this.message = message;
    }

    /**
     * @param responseEnum 响应枚举
     */
    public BusinessException(ResponseEnum responseEnum) {
        code = responseEnum.getCode();
        message = responseEnum.getMessage();
    }

    /**
     * @param responseEnum 响应枚举
     * @param throwable    原始异常对象
     */
    public BusinessException(ResponseEnum responseEnum, Throwable throwable) {
        super(throwable);
        code = responseEnum.getCode();
        message = responseEnum.getMessage();
    }

}
